<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <ul>
      <li v-for="(item, index) of list" :key="index">
        {{ item.area }}
      </li>
    </ul>
  </div>
</body>
<script src="lib/vue.js"></script>
<script src="lib/axios.js"></script>
<script>

  // 请求拦截器
  axios.interceptors.request.use(config => {
    // config 可以看作是 axios({}) 中的 {}
    console.log('正在加载')
    config.headers.common.token = 'my-token'
    return config
  }, err => {
    return Promise.reject(err);
  })

  // 响应拦截器
  axios.interceptors.response.use(response => {
    console.log('加载结束')
    // 条件判断，判断token的有效性，如果无效，直接跳转到登录页面
    return response
  }, err => {
    return Promise.reject(err);
  })

  new Vue({
    el: '#app',
    data: {
      list: []
    },
    methods: {
      getCity () {
        return axios.get('https://api.i-lynn.cn/college')
      },
      postLogin () {
        return axios.post('http://121.89.205.189/api/user/login', {
          loginname: '18813007814', password: '123456'
        })
      },
      getProList () {
        return axios.get('http://121.89.205.189/api/pro/list', {
          params: {
            limitNum: 100
          }
        })
      }
    },
    mounted () {
      // Promise.all([this.getCity(), this.postLogin(), this.getProList()]).then(res => {
      //   console.log(res[0].data)
      //   console.log(res[1].data)
      //   console.log(res[2].data)
      // })
      axios.all([this.getCity(), this.postLogin(), this.getProList()]).then(axios.spread((citys, login, prolist) => {
        console.log(citys.data)
        console.log(login.data)
        console.log(prolist.data)
      }))
    }
  })
</script>
</html>